﻿using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;

namespace _01_Tower
{
    internal class Game
    {
        long currentTime, lastTime;
        int fps;
        public bool isOver;
        

        Hero hero;
        Monster monster;
        Map map;
        Information info;
        Input input;
        HPBar hpbar;

        public Game()
        {
            hero = new Hero();
            monster = new Monster();
            map = new Map();
            input = new Input();
            info = new Information(80,2,50,input);
            hpbar = new HPBar(82,1,20,hero);
        }

        void Init()
        {
            isOver = false;
            currentTime = lastTime = 0;
            fps = 60;
            Console.CursorVisible = false;
            Console.SetWindowSize(120,30);
            Console.SetBufferSize(120,30);

            map.Init();
            hero.Init(map,info,monster,input,hpbar);

            
        }
        void Input()
        {
            info.Input();
            hero.Input();
        }
        void Update()
        {
            monster.Update();
            info.Update();
            map.Update();
            hero.Update();

        }
        void Render()
        {
            hpbar.Render();
            map.Render();
            hero.Render();
            info.PrintInfo();
        }
        void End()
        {
           
        }
        public void Play()
        {
            Init();

            lastTime = DateTime.Now.Ticks;
            while (!isOver)
            {
                input.Update();
                Input();
                Update();
                currentTime = DateTime.Now.Ticks;
                
                if (currentTime - lastTime > 10_000_000 / fps)
                {
                    Render();
                    lastTime = DateTime.Now.Ticks;
                }
            }
            End();
        }

        
    }
}
